﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Text;

public partial class Interviewer_InterviewerProposedInterview : System.Web.UI.Page
{
    InterviewerMethord IM = new InterviewerMethord();
    string Interview = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            txtDateInterview_CalendarExtender.StartDate = DateTime.Now;
            Interview = Request.QueryString["ID"].ToString();
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        catch (Exception ex)
        {
        }
    }
    public void LoadData()
    {
        DataTable tb = IM.ReturnInformationInterview(Interview);
        foreach (DataRow item in tb.Rows)
        {
            txtInterviewerID.Text = "<a href='InterviewerInformation.aspx'>"+item["InterviewerID"].ToString()+"</a>";
            txtVacancyID.Text = "<a href='InterviewerViewVacancyDetails.aspx?ID=" + item["VacancyID"].ToString() + "'>" + item["VacancyID"].ToString() + "</a>";
            txtApplicantID.Text = "<a href='InterviewerViewApplicantInformation.aspx?ID=" + item["ApplicantID"].ToString() + "'>" + item["ApplicantID"].ToString() + "</a>";
            txtDateInterview.Text = item["DateInterview"].ToString().Substring(0, item["DateInterview"].ToString().IndexOf(" "));
            txtTime.Text = item["TimeDetails"].ToString();
        }
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        lblError.Text = "";
        if (txtDateInterview.Text.Equals(""))
        {
            lblError.Text = "Data Interview can not be empty.";
        }
        else if (txtTime.Text.Equals(""))
        {
            lblError.Text = "Time Interview can not be empty.";
        }
        else
        {
            try
            {
                Convert.ToDateTime(txtDateInterview.Text);
                bool check = false;
                XmlTextWriter xmlwriter = new XmlTextWriter(Server.MapPath("~/ProposedInterview/" + IM.ReturnHRFollowInterviewID(Interview) + "_"+Interview+".xml"), Encoding.UTF8);
                xmlwriter.Formatting = Formatting.Indented;
                xmlwriter.WriteStartDocument();
                xmlwriter.WriteStartElement("Interview");
                DataTable tb = IM.ReturnInformationInterview(Interview);
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    xmlwriter.WriteElementString("InterviewID", Interview);
                    xmlwriter.WriteElementString("InterviewerID", tb.Rows[i]["InterviewerID"].ToString());
                    xmlwriter.WriteElementString("VacancyID", tb.Rows[i]["VacancyID"].ToString());
                    xmlwriter.WriteElementString("ApplicantID", tb.Rows[i]["ApplicantID"].ToString());
                    xmlwriter.WriteElementString("DateInterview", txtDateInterview.Text);
                    xmlwriter.WriteElementString("TimeDetails", txtTime.Text);
                }
                xmlwriter.WriteEndElement();
                xmlwriter.WriteEndDocument();
                xmlwriter.Flush();
                xmlwriter.Close();
                check = true;
                if (!check)
                {
                    lblError.Text = "Faild";
                }
                else
                {
                    Response.Write("<script type='text/javascript'>alert('Proposed successful.'); window.location = 'InterviewViewInterviewInfor.aspx'</script>");
                }
            }
            catch (FormatException fr)
            {
                lblError.Text = "Date interview wrong.";
            }
            catch (Exception ex)
            {
            }
        }
    }
}